<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            userscore: [
                {
                    username: "老王",
                    score: 60
                },
                {
                    username: "老李",
                    score: 70
                },
                {
                    username: "老高",
                    score: 80
                },
                {
                    username: "老洪",
                    score: 90
                }
            ],

        };
        // 求平均值和总分数

        let userscores = obj.userscore
        let sum = 0
        userscores.forEach(function (iteam, index) {
            sum = sum + Number(iteam.score)
        })
        let count = sum / Number(userscores.length)
        console.log("总分数是" + sum)
        console.log("平均分数是" + count)

        let newobj = Object.defineProperties(obj, {
            score: {
                get: function () {
                    return "总分数是" + sum;
                }
            },
            avg: {
                get: function () {
                    return "平均分数是" + count;
                }

            }

        })
        console.log(newobj)
        // 尾插
        userscores.push({
            username: "老刘",
            score: 100

        })
        console.log(userscores)

        // 王菲
        // ------------------------------------------------------------------------------------------------------------

        let {name:username,age,songs:[one,two,thress,five],history:[{name:name1},{name:name2},{name:name3}]} = {
            name: '王菲',
            age: 18,
            songs: ['红豆', '流年', '暧昧', '传奇'],
            history: [
                { name: '窦唯' },
                { name: '李亚鹏' },
                { name: '谢霆锋' }
            ]
        };
        console.log(username,age,one,two,thress,five,name1,name2,name3)

    </script>
</body>

</html>